#include "bufstream.h"


template< class type >
bufstream& bufstreamin( bufstream& stream, type v )	{ stream.putn( (xgc_byte*)&v, sizeof(v) ); return stream; }

template< class type >
bufstream& bufstreamout( bufstream& stream, type &v )	{ stream.getn( (xgc_byte*)&v, sizeof(type) ); return stream; }

bufstream& operator << ( bufstream& stream, bool c )			{ return bufstreamin< bool >( stream, c ); }
bufstream& operator << ( bufstream& stream, char c )			{ return bufstreamin< char >( stream, c ); }
bufstream& operator << ( bufstream& stream, short c )			{ return bufstreamin< short >( stream, c ); }
bufstream& operator << ( bufstream& stream, int c )				{ return bufstreamin< int >( stream, c ); }
bufstream& operator << ( bufstream& stream, long c )			{ return bufstreamin< long >( stream, c ); }
bufstream& operator << ( bufstream& stream, long long c )		{ return bufstreamin< long long >( stream, c ); }
bufstream& operator << ( bufstream& stream, unsigned char c )	{ return bufstreamin< unsigned char >( stream, c ); }
bufstream& operator << ( bufstream& stream, unsigned short c )	{ return bufstreamin< unsigned short >( stream, c ); }
bufstream& operator << ( bufstream& stream, unsigned int c )	{ return bufstreamin< unsigned int >( stream, c ); }
bufstream& operator << ( bufstream& stream, unsigned long c )	{ return bufstreamin< unsigned long >( stream, c ); }
bufstream& operator << ( bufstream& stream, unsigned long long c ){ return bufstreamin< unsigned long long >( stream, c ); }
bufstream& operator << ( bufstream& stream, float c )			{ return bufstreamin< float >( stream, c ); }
bufstream& operator << ( bufstream& stream, double c )			{ return bufstreamin< double >( stream, c ); }
bufstream& operator << ( bufstream& stream, long double c )		{ return bufstreamin< long double >( stream, c ); }
bufstream& operator << ( bufstream& stream, const std::string &c )
{
	stream.putn( (xgc_byte*)c.c_str(), c.length()+1 );
	return stream;
}

bufstream& operator << ( bufstream& stream, const std::wstring &c )
{
	stream.putn( (xgc_byte*)c.c_str(), (c.length()<<1)+sizeof( wchar_t/*std::wstring::traits_type::char_type*/ ) );
	return stream;
}

bufstream& operator << ( bufstream& stream, const xgc_lpcstr c )
{
	stream.putn( (xgc_byte*)c, strlen(c)+1 );
	return stream;
}

bufstream& operator << ( bufstream& stream, const xgc_lpcwstr c )
{
	stream.putn( (xgc_byte*)c, (wcslen(c)+1)*sizeof(wchar_t) );
	return stream;
}

bufstream& operator >> ( bufstream& stream, bool &c )			{ return bufstreamout< bool >( stream, c ); }
bufstream& operator >> ( bufstream& stream, char &c )			{ return bufstreamout< char >( stream, c ); }
bufstream& operator >> ( bufstream& stream, short &c )			{ return bufstreamout< short >( stream, c ); }
bufstream& operator >> ( bufstream& stream, int &c )			{ return bufstreamout< int >( stream, c ); }
bufstream& operator >> ( bufstream& stream, long &c )			{ return bufstreamout< long >( stream, c ); }
bufstream& operator >> ( bufstream& stream, long long &c )		{ return bufstreamout< long long >( stream, c ); }
bufstream& operator >> ( bufstream& stream, unsigned char &c )	{ return bufstreamout< unsigned char >( stream, c ); }
bufstream& operator >> ( bufstream& stream, unsigned short &c )	{ return bufstreamout< unsigned short >( stream, c ); }
bufstream& operator >> ( bufstream& stream, unsigned int &c )	{ return bufstreamout< unsigned int >( stream, c ); }
bufstream& operator >> ( bufstream& stream, unsigned long &c )	{ return bufstreamout< unsigned long >( stream, c ); }
bufstream& operator >> ( bufstream& stream, unsigned long long &c){ return bufstreamout< unsigned long long >( stream, c ); }
bufstream& operator >> ( bufstream& stream, float &c )			{ return bufstreamout< float >( stream, c ); }
bufstream& operator >> ( bufstream& stream, double &c )			{ return bufstreamout< double >( stream, c ); }
bufstream& operator >> ( bufstream& stream, long double &c )	{ return bufstreamout< long double >( stream, c ); }
bufstream& operator >> ( bufstream& stream, std::string &c )
{
	c = (xgc_lpcstr)stream.rd_ptr();
	stream.seekoff( c.length()+1, bufstream::cur, bufstream::out );
	return stream;
}

bufstream& operator >> ( bufstream& stream, std::wstring &c )
{
	c = (xgc_lpcwstr)stream.rd_ptr();
	stream.seekoff( (c.length()<<1)+sizeof(xgc_wchar), bufstream::cur, bufstream::out );
	return stream;
}

bufstream& operator >> ( bufstream& stream, xgc_lpcstr &c )
{
	c = (xgc_lpcstr)stream.rd_ptr();
	stream.seekoff( strlen(c)+1, bufstream::cur, bufstream::out );
	return stream;
}

bufstream& operator >> ( bufstream& stream, xgc_lpcwstr &c )
{
	c = (xgc_lpcwstr)stream.rd_ptr();
	stream.seekoff( (wcslen(c)<<1)+sizeof(xgc_wchar), bufstream::cur, bufstream::out );
	return stream;
}
